using System;
using System.Collections.Generic;
using System.ComponentModel;

using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CodePlex.SpaceBlock;
using CodePlex.Resourceful;
using CodePlex.Resourceful.Amazon.S3;

namespace CodePlex.SpaceBlock.UI.Controls
{
    public partial class ExceptionForm : CodePlex.SpaceBlock.UI.Controls.BaseForm
    {
        public ExceptionForm()
        {
            InitializeComponent();

            this.Text = Properties.Messages.ExceptionForm_Title;
            this.StartPosition = FormStartPosition.CenterScreen;
            bool showDetail = false;

            Operation render = delegate
            {
                if (showDetail)
                {
                    _detailButton.Text = "<< Hide Detail";
                    // _detailButton.Image = UIManager.Instance.SmallImageList.Images[10];

                    this.Height = 355;
                }
                else
                {
                    _detailButton.Text = "Show Detail >>";
                    // _detailButton.Image = UIManager.Instance.SmallImageList.Images[11];

                    this.Height = 170;
                }
            };
            _detailButton.Click += delegate
            {
                showDetail = !showDetail;

                render();
            };

            render();
        }



       

        public void Show(Exception ex) {

            _messageBox.Text = ex.Message;
            _detailBox.Text = ex.ToString();


            S3Exception e = ex as S3Exception;

            _fieldsBox.Text = "";

            if (e == null || e.Fields == null)
            {
                
            }
            else
            {
                foreach (string key in e.Fields.Keys)
                {
                    _fieldsBox.Text += key + ": " + e.Fields[key] + "\r\n";
                }
            }

            tabControl1.SelectedIndex = 0;
            this.ShowDialog();
        }

    }
}

